/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogChats.java
 *
 * Created on 24.06.2011, 9:20:11
 */
package ru.icq.gui.dialogs;

import org.apache.log4j.Logger;
import ru.icq.gui.panels.ButtonTabComponent;
import ru.icq.gui.panels.PanelChat;
import ru.icq.accounts.EntryjICQ;

/**
 * Диалоговое окно для отображения чатов.
 * @author Носов А.В.
 */
public class DialogChats extends javax.swing.JDialog {

    // Variables declaration
    private static final Logger log = Logger.getLogger(DialogChats.class);
    // End of variables declaration

    /** Creates new form DialogChats */
    public DialogChats(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabbedPaneChats = new javax.swing.JTabbedPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().add(tabbedPaneChats, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public void addChat(EntryjICQ entryjICQ) {
        int index = tabbedPaneChats.indexOfTab(entryjICQ.getUser());
        
        if (index == -1) {
            tabbedPaneChats.addTab(entryjICQ.getUser(), new PanelChat(entryjICQ));
            tabbedPaneChats.setTabComponentAt(tabbedPaneChats.getTabCount()-1, new ButtonTabComponent(tabbedPaneChats));
            tabbedPaneChats.setSelectedIndex(tabbedPaneChats.getTabCount()-1);
        } else {
            tabbedPaneChats.setSelectedIndex(index);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                DialogChats dialog = new DialogChats(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTabbedPane tabbedPaneChats;
    // End of variables declaration//GEN-END:variables
}
